package com.mvp.mvpdemo.activity

import com.cxz.wanandroid.ext.loge
import com.mvp.mvpdemo.R
import com.mvp.mvpdemo.base.BaseMvpActivity
import com.mvp.mvpdemo.bean.LoginBean
import com.mvp.mvpdemo.mvp.contract.LoginContract
import com.mvp.mvpdemo.mvp.presenter.LoginPresenter
import kotlinx.android.synthetic.main.activity_login.*
import java.io.File

/**
 * Created By Mahongyin
 * Date    2020/10/15 16:38
 *
 */
class LoginActivity : BaseMvpActivity<LoginContract.View, LoginContract.Presenter>(),
    LoginContract.View {

    override fun createPresenter(): LoginPresenter = LoginPresenter()


    override fun getLayoutId(): Int = R.layout.activity_login

    override fun initCreate() {

    }

    override fun initData() {
        button.setOnClickListener { mPresenter?.login("myname", "mahongyin") }
        button2.setOnClickListener { mPresenter?.logout() }
        val file= File("/storage/emulated/0/parser1.jpg")

        button5.setOnClickListener { mPresenter?.upLaodFile(file) }
        button6.setOnClickListener { mPresenter?.upLaodFiles("user", "userabc", file) }

    }


    override fun loginSusscess(result: LoginBean) {
        showLongToast("登录成功${result.toString()}")
        goActivity(MainActivity::class.java)
    }

    override fun logoutSusscess(result: LoginBean) {
        showLongToast("退出成功${result.toString()}")

    }

    override fun error(error: String) {
        loge(error)
        showShortToast(error)
    }


}